//
//  UWOConstant.h
//  basic
//
//  Created by Jack on 2016/12/15.
//  Copyright © 2016年 Jack. All rights reserved.
//

#ifndef UWOConstant_h
#define UWOConstant_h

/**
 *  系统版本
 */
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)

#define   IOS7    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")
#define   IOS8    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0")
#define   IOS9    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")
#define   IOS10    SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10.0")

/**
 *  APP版本号
 */
#define   APP_VERSION   ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"])
#define   Build_VERSION  ([[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"])


/**
 *  屏幕宽度、高度
 */
#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height

/**
 *  Color
 */
#define RGBColor(r,g,b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define RGBColorAlpha(r,g,b,a) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]

#define UWO_colorWithHex(hexColor) \
\
+ (UIColor *)colorWithHex:(NSString *)hexColor{\
    if (hexColor == nil) {\
        return nil;\
    }\
    if ([hexColor length] < 7 ) {\
        return nil;\
    }\
    unsigned int red, green, blue;\
    NSRange range;\
    range.length = 2;\
    range.location = 1;\
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&red];\
    range.location = 3;\
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&green];\
    range.location = 5;\
    [[NSScanner scannerWithString:[hexColor substringWithRange:range]] scanHexInt:&blue];\
    return [UIColor colorWithRed:(float)(red/255.0f) green:(float)(green/255.0f) blue:(float)(blue/255.0f) alpha:1.0f];\
}\

#define UWOWhite [UIColor whiteColor]

/**
 *  NSNotificationCenter
 */
#define UWONotificationCenter [NSNotificationCenter defaultCenter]

/**
 *  NSUserDefaults
 */
#define UWOUserDefault [NSUserDefaults standardUserDefaults]

/**
 *  单例
 */

#define UWO_SINGLETON_FOR_HEADER(className) \
\
+ (className *)shared##className;

#define UWO_SINGLETON_FOR_CLASS(className) \
\
+ (className *)shared##className { \
static className *shared##className = nil; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
shared##className = [[self alloc] init]; \
}); \
return shared##className; \
}


/**
 *  NIBVIEW
 */

#define UWO_NIBVIEW_FOR_HEADER(className) \
\
+(className *)instanceNibView;

#define UWO_NIBVIEW_FOR_CLASS(className) \
\
+(className *)instanceNibView{\
NSArray* nibView =  [[NSBundle mainBundle] loadNibNamed:NSStringFromClass([className class]) owner:nil options:nil];\
className *view = nibView.firstObject;\
return view;\
}


/**
 *  DLog
 */
#ifdef DEBUG
#ifndef DLog
#   define DLog(fmt, ...) {NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);}
#endif
#ifndef ELog
#   define ELog(err) {if(err) DLog(@"%@", err)}
#endif
#else
#ifndef DLog
#   define DLog(...)
#endif
#ifndef ELog
#   define ELog(err)
#endif
#endif

//  UWORGB_COLOR
#define UWORGB_COLOR(r,g,b) [UIColor colorWithRed:(float)(r/255.0f) green:(float)(g/255.0f) blue:(float)(b/255.0f) alpha:1.0f]
#define UWORGB_COLOR_ALPHA(r,g,b,a) [UIColor colorWithRed:(float)(r/255.0f) green:(float)(g/255.0f) blue:(float)(b/255.0f) alpha:a]

#endif /* UWOConstant_h */
